var engine = {
	DirtyRenderer : function(canvas, stage, framerate) {
		this._canvas = canvas;
		this._stage = stage;
		this._intervalId = null;
		this._framerate = framerate;
		
		this._context = this._canvas.getContext('2d');
		
		this._backBuffer = document.createElement('canvas');
		this._backBuffer.setAttribute('style', 'display: none');
        this._backBuffer.width = this._canvas.width;
        this._backBuffer.height = this._canvas.height;
        this._backBufferContext2D = this._backBuffer.getContext('2d');
	}
}

engine.DirtyRenderer.prototype = {
	start: function() {
		_self = this;
		this._intervalId = setInterval(function(){_self.processFrame()}, this._framerate);
	},
	stop: function() {
		clearInterval(this._intervalId);
	},
	processFrame: function() {
		this.layoutStage();
		this.renderStage();
	},
	layoutStage: function() {
		this._stage.layout(this._backBufferContext2D);
	},
	renderStage: function() {
		this._stage.render(this._backBufferContext2D);
		
		this._context.drawImage(this._backBuffer,0,0);
	}
}
